import { ConfigEnv, UserConfigExport, loadEnv, defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'  //配置@根路径
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' //导入svg
import { viteMockServe } from 'vite-plugin-mock' //引入mockjs数据
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
  return {
    plugins: [
      vue(),
    //全局导入svg
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
      symbolId: 'icon-[dir]-[name]',
    }),
    //导入mockjs数据
    viteMockServe({
      localEnabled: command === 'serve',
    }),
    ],
    resolve: {
      //全局配置别名
      alias: {
        "@": path.resolve("./src")
      },
      extensions: ['.js', '.json', '.ts', '.vue']
    },
    //导入全局样式
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss";',
        },
      },
    },
    
  }
}
